######################################
#
######################################
#source file
SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))

#target you can change to test any you want
TARGET  := main

#compile and lib parameter

CC      := gcc
CXX     := g++
LIBS    :=
LDFLAGS := -lcblas -lrefblas -llapacke -llapack -lgfortran
DEFINES :=
INCLUDE := -I include/
CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)
CXXFLAGS:= $(CFLAGS)

.PHONY : objs clean
all:
	$(CXX) $(CXXFLAGS) -o main main.cpp $(LDFLAGS)
	./main > result.txt

objs : $(OBJS)

clean :
	rm -fr *.so
	rm -fr *.o	
	rm -fr $(TARGET)

testall:
	@echo ----------------------------Test for Vec---------------------------------------- > test.txt
	@cd test/ && make testvec
	@cd test/ && ./testvec>>../test.txt
	@echo ----------------------------Test for Polynomial--------------------------------- >> test.txt
	@cd test/ && make testpoly
	@cd test/ && ./testpoly>>../test.txt
	@echo ----------------------------Test for spline of ppform--------------------------- >> test.txt
	@cd test/ && make testspline
	@cd test/ && ./testspline>>../test.txt
	@echo ----------------------------Test for B-spline----------------------------------- >> test.txt
	@cd test/ && make testBspline
	@cd test/ && ./testBspline>>../test.txt
	@echo ----------------------------Test for spline of Bform---------------------------- >> test.txt
	@cd test/ && make testBFormspline
	@cd test/ && ./testBFormspline>>../test.txt
	@echo ----------------------------Test for knots-helper------------------------------- >> test.txt
	@cd test/ && make testKnotsHelper
	@cd test/ && ./testKnotsHelper>>../test.txt
	@echo ----------------------------Test for spline of cardinalB------------------------ >> test.txt
	@cd test/ && make testCardinalBspline
	@cd test/ && ./testCardinalBspline>>../test.txt
	@echo Use "make cleantest" to clean all executable test. >> test.txt
cleantest:
	@cd test/ && make clean
report:
	xelatex report
	xelatex report
	rm report.log report.aux
check:
	valgrind ./main
